﻿using System.Collections.Generic;
using GIMS.Def.Settings;
using GIMS.GUI.ArgumentControls;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;
using GIMS.Def.Arguments;
using System.ComponentModel;

namespace GIMS.GUI.Test
{
    /// <summary>
    ///This is a test class for GeometryArgumentControlViewModelTest and is intended
    ///to contain all GeometryArgumentControlViewModelTest Unit Tests
    ///</summary>
    [TestClass()]
    public class GeometryArgumentControlViewModelTest
    {
        /// <summary>
        /// Reset GlobalSettings
        /// </summary>
        [TestInitialize()]
        public void MyTestInitialize()
        {
            GlobalSettings_Accessor.instance = null;
        }

        /// <summary>
        ///A test for InitGeometryTypeValues
        ///</summary>
        [TestMethod()]
        [DeploymentItem("GIMS.GUI.exe")]
        public void InitGeometryTypeValuesTest()
        {
            GeometryArgumentControlViewModel_Accessor viewModel = new GeometryArgumentControlViewModel_Accessor();
            var argument = new GeometryArgument(GeometryType.height | GeometryType.width | GeometryType.area | GeometryType.widthxheight | GeometryType.offsetNeeded, GeometryType.widthxheight);
            viewModel.GeometryArgument = argument;
            viewModel.InitGeometryTypeValues();
            Assert.AreEqual(4, viewModel.GeometryTypeRepresenters.Count());
            Assert.IsNotNull(viewModel.GeometryTypeRepresenters.First(p => p.Name == "height"));
            Assert.IsNotNull(viewModel.GeometryTypeRepresenters.First(p => p.Name == "width"));
            Assert.IsNotNull(viewModel.GeometryTypeRepresenters.First(p => p.Name == "area"));
            Assert.IsNotNull(viewModel.GeometryTypeRepresenters.First(p => p.Name == "widthxheight"));
        }

        /// <summary>
        ///A test for HasMoreThenOneGeometryType
        ///</summary>
        [TestMethod()]
        public void HasMoreThenOneGeometryTypeTest()
        {
            var argument = new GeometryArgument(GeometryType.height | GeometryType.width | GeometryType.area | GeometryType.widthxheight | GeometryType.offsetNeeded, GeometryType.widthxheight);
            GeometryArgumentControlViewModel target = new GeometryArgumentControlViewModel(argument);
            bool actual = target.HasMoreThenOneGeometryType;
            Assert.AreEqual(true, actual);

            argument = new GeometryArgument(GeometryType.area, GeometryType.area);
            target = new GeometryArgumentControlViewModel(argument);
            actual = target.HasMoreThenOneGeometryType;
            Assert.AreEqual(false, actual);
        }


        /// <summary>
        ///A test for IsArea
        ///</summary>
        [TestMethod()]
        public void IsAreaTest()
        {
            var argument = new GeometryArgument(GeometryType.area, GeometryType.area);
            GeometryArgumentControlViewModel target = new GeometryArgumentControlViewModel(argument);
            bool actual = target.IsArea;
            Assert.AreEqual(true, actual);

            argument = new GeometryArgument(GeometryType.widthxheight, GeometryType.widthxheight);
            target = new GeometryArgumentControlViewModel(argument);
            actual = target.IsArea;
            Assert.AreEqual(false, actual);
        }

        /// <summary>
        ///A test for IsHeigth
        ///</summary>
        [TestMethod()]
        public void IsHeigthTest()
        {
            var argument = new GeometryArgument(GeometryType.height, GeometryType.height);
            GeometryArgumentControlViewModel target = new GeometryArgumentControlViewModel(argument);
            bool actual = target.IsHeigth;
            Assert.AreEqual(true, actual);

            argument = new GeometryArgument(GeometryType.widthxheight, GeometryType.widthxheight);
            target = new GeometryArgumentControlViewModel(argument);
            actual = target.IsHeigth;
            Assert.AreEqual(true, actual);

            argument = new GeometryArgument(GeometryType.area, GeometryType.area);
            target = new GeometryArgumentControlViewModel(argument);
            actual = target.IsHeigth;
            Assert.AreEqual(false, actual);
        }

        /// <summary>
        ///A test for IsOffsetNeeded
        ///</summary>
        [TestMethod()]
        public void IsOffsetNeededTest()
        {
            var argument = new GeometryArgument(GeometryType.widthxheight | GeometryType.offsetNeeded, GeometryType.widthxheight | GeometryType.offsetNeeded);
            GeometryArgumentControlViewModel target = new GeometryArgumentControlViewModel(argument);
            bool actual = target.IsOffsetNeeded;
            Assert.AreEqual(true, actual);

            argument = new GeometryArgument(GeometryType.widthxheight, GeometryType.widthxheight);
            target = new GeometryArgumentControlViewModel(argument);
            actual = target.IsOffsetNeeded;
            Assert.AreEqual(false, actual);
        }

        /// <summary>
        ///A test for IsPercent
        ///</summary>
        [TestMethod()]
        public void IsPercentTest()
        {
            var argument = new GeometryArgument(GeometryType.percent, GeometryType.percent);
            GeometryArgumentControlViewModel target = new GeometryArgumentControlViewModel(argument);
            bool actual = target.IsPercent;
            Assert.AreEqual(true, actual);

            argument = new GeometryArgument(GeometryType.widthxheight, GeometryType.widthxheight);
            target = new GeometryArgumentControlViewModel(argument);
            actual = target.IsPercent;
            Assert.AreEqual(false, actual);
        }

        /// <summary>
        ///A test for IsWidth
        ///</summary>
        [TestMethod()]
        public void IsWidthTest()
        {
            var argument = new GeometryArgument(GeometryType.width, GeometryType.width);
            GeometryArgumentControlViewModel target = new GeometryArgumentControlViewModel(argument);
            bool actual = target.IsWidth;
            Assert.AreEqual(true, actual);

            argument = new GeometryArgument(GeometryType.widthxheight, GeometryType.widthxheight);
            target = new GeometryArgumentControlViewModel(argument);
            actual = target.IsWidth;
            Assert.AreEqual(true, actual);

            argument = new GeometryArgument(GeometryType.area, GeometryType.area);
            target = new GeometryArgumentControlViewModel(argument);
            actual = target.IsWidth;
            Assert.AreEqual(false, actual);
        }

        /// <summary>
        ///A test for IsxyPercent
        ///</summary>
        [TestMethod()]
        public void IsxyPercentTest()
        {
            var argument = new GeometryArgument(GeometryType.percent, GeometryType.percent);
            GeometryArgumentControlViewModel target = new GeometryArgumentControlViewModel(argument);
            bool actual = target.IsPercent;
            Assert.AreEqual(true, actual);

            argument = new GeometryArgument(GeometryType.widthxheight, GeometryType.widthxheight);
            target = new GeometryArgumentControlViewModel(argument);
            actual = target.IsPercent;
            Assert.AreEqual(false, actual);
        }

        /// <summary>
        ///A test for GeometryArgument_PropertyChanged. Raised by changing the SelectedGeometryType.
        ///</summary>
        [TestMethod()]
        [DeploymentItem("GIMS.Def.dll")]
        public void GeometryArgument_PropertyChangedTest()
        {
            var argument = new GeometryArgument(GeometryType.percent | GeometryType.xypercent, GeometryType.percent);
            GeometryArgumentControlViewModel viewModel = new GeometryArgumentControlViewModel(argument);

            List<string> receivedEvents = new List<string>();
            viewModel.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                receivedEvents.Add(e.PropertyName);
            };

            argument.SelectedGeometryType = GeometryType.xypercent;
            Assert.AreEqual(6, receivedEvents.Count);
        }
    }
}
